######################################
#
#
######################################

#target you can change test to what you want
#共享库文件名，lib*.so
TARGET  := libtest.so

#compile and lib parameter
#编译参数
CC      := g++
LIBS    :=
LDFLAGS :=
DEFINES :=
INCLUDE := -I.
CFLAGS  := -g -Wall -O3 $(DEFINES) $(INCLUDE)
CXXFLAGS:= $(CFLAGS) -DHAVE_CONFIG_H
SHARE   := -fpic -shared -o
  
#i think you should not fix anything here
#下面的基本上不需要做任何改动了
  
#source file
#源文件，自动找所有.c和.cpp文件，并将目标定义为同名.o文件
SOURCE  := $(wildcard *.c) $(wildcard *.cpp)
OBJS    := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE)))
#头文件，自动查找.h文件
HEADER := $(wildcard *.h)

.PHONY : everything objs clean veryclean rebuild install

everything : $(TARGET)

all : $(TARGET)

objs : $(OBJS)
	$(CC) -c -fPIC $(SOURCE)

rebuild: veryclean everything
         
clean :
	rm -fr *.o
    
veryclean : clean
	rm -fr $(TARGET)

install :
	test -d ./sample/lib && echo ' ' || mkdir ./sample/lib
	cp $(TARGET) ./sample/lib/
	test -d ./sample/include/ && echo ' ' || mkdir ./sample/include
	cp $(HEADER) ./sample/include/

$(TARGET) : objs
	$(CC) $(CXXFLAGS) $(SHARE) $@ $(OBJS) $(LDFLAGS) $(LIBS)